# -*- coding: utf8 -*-
class Human(object):
    def __init__(self,mhp,hp,mov=2,atk=10,defend=5,exp=0,name='ppl'):
        self.mhp=mhp   # 最大HP
        self.hp=hp
        self.mov=mov   # your move
        self.atk=atk  # your atk
        self.defend=defend    # your defend
        self.atk_add = 0  # your bangkill
        self.exp = exp # 人物经验
        self.name = name
        self.mround = 0 # 各种行为消耗值
        self.newAtk=self.atk
        self.newDefend=self.defend
        self.position = ()
        if self.hp>self.mhp:self.hp=self.mhp
    
    def getLevel(self):
        '''获取人物等级'''
        return self.exp/100+1
    heroLV = property(getLevel)

    def equip(self,equipment):
        if equipment.owner==0 and self.heroLV>=equipment.lv:
            self.newAtk=self.atk+equipment.atk
            self.newDefend=self.defend+equipment.defend
            equipment.owner = 1
            return True
        return False
    def useItem(self,item):
        self.hp += item.hp
        self.atk += item.atk
        self.mov += item.mov
        self.defend += item.defend
        self.mround = self.mround - 2 #计算行为值
        if self.hp>self.mhp:self.hp=self.mhp
        del item
#    def isBang(self):
#        '''判断是否发生了暴击的方法'''
#        if random.randint(1,1000) in range(1,51):
#            return True
#        return False
#    
#    def bang(self,enemy):
#        '''暴击'''
#        self.atk_add = int(self.newAtk*0.5)
#        return self.realAttack(enemy)
#        
#    def normalAttack(self,enemy):
#        '''普通攻击'''
#        self.atk_add = 0
#        return self.realAttack(enemy)
    def atkRound(self,enemy):
        a,b=self.position
        c,d=enemy.position
        if abs(a-c)+abs(b-d)==1:
            return True
        return False
    def attack(self,enemy,bang=None):
        '''计算产生何种攻击方式'''
        if self.atkRound(enemy):
            if random.randint(1,1000) in range(1,51) or bang==1:
                self.atk_add = int(self.newAtk*0.5)
                return self.realAttack(enemy)
            elif random.randint(1,1000) in range(52,1000) or bang==0:
                self.atk_add = 0
                return self.realAttack(enemy)
        return False
    def realAttack(self,enemy):
        '''根据公式真实攻击'''
        damage=self.newAtk+self.atk_add-enemy.defend
        enemy.hp=enemy.hp-damage
        self.mround = self.mround-2 #计算行为值
        skill = Skill(self,enemy) # 经验模块
        if self.atk_add==0:
            return enemy.hp,False
        return enemy.hp,True

    def isOver(self):
        '''判断自己是否已经死亡'''
        print 'HP:' ,self.hp
        if self.hp<=0:
            print 'you dead'
            return True
        return False
    
    #此方法失效，暂时取消
    #def isRoundOver(self):
    #    '''判断自己的回合内还能否继续行动'''
    #    if mround == 0:
    #        mround = 2
    #        return True
    #    return False
    #!C:\Python26\Python.exe

